<template>
	<view class="collect" :class="{'none': noMoreList}">
		<uni-nav-bar :fixed="true" left-icon="back" :border="false" backgroundColor="#f9f2ea" leftText="喜欢"
			:statusBar="true" @clickLeft="goBack"></uni-nav-bar>
		<view class="head">
			<view class="nav">
				<view class="nav-box" @click="navChange('1')">
					<view class="nav-item" :class="{'active': navChoose == 1}">
						商品
					</view>
				</view>
				<view class="nav-box" @click="navChange('3')">
					<view class="nav-item" :class="{'active': navChoose == 3}">
						作品
					</view>
				</view>
			</view>
		</view>
		<view class="art">
			<view class="art-item flex" v-for="(item, index) in collectArr" :key="index"
				@click="toArtwork(item.info_id)">
				<image class="img" :src="item.thumb" mode=""></image>
				<view class="content">
					<view class="content-title">
						{{item.name}}
					</view>
					<view class="type">
						<text>{{item.spec_name}}</text>

					</view>
					<view class="price">
						￥{{item.price}}
					</view>

				</view>
				<view class="btn" @tap.stop="cancelShow(item.info_id, index)">
					取消喜欢
				</view>
			</view>
		</view>
		<view class="nomore" v-if="noMoreList">
			<!-- <image class="haveno" src="../../static/collect_none.png" mode=""></image> -->
			<view>暂无数据</view>
		</view>
		<uni-load-more v-show="loadMoreShow" :status="loadMoreStatus"></uni-load-more>
	</view>
</template>

<script>
	import {
		userCollectList,
		cancelCollect
	} from "@/api/public.js"
	import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue"
	export default {
		data() {
			return {
				navChoose: 1,
				collectArr: [],
				loadMoreShow: false,
				loadMoreStatus: "more",
				noMoreList: false,
				page: 1,
			}
		},
		created() {
			this.getList();
		},
		methods: {
			goBack() {
				uni.navigateBack();
			},
			navChange(type) {
				this.navChoose = type;
				this.page = 1;
				this.collectArr = [];
				this.getList();
			},
			getList() {
				userCollectList(this.page, this.navChoose).then(res => {
					if (this.page == 1) {
						if (!res.reData.data || res.reData.data.length == 0) {
							this.noMoreList = true
						} else {
							this.noMoreList = false
							this.showLoadMore = true
						}
					}
					if (res.reData.data) {
						let newData = res.reData.data;
						this.collectArr = this.collectArr.concat(newData);
						if (res.reData.data.length < 10) {
							this.loadMoreStatus = 'noMore';
						} else {
							this.loadMoreStatus = 'more';
						}
					}
				})
			},
			// toExhibit(id){
			// 	uni.navigateTo({
			// 		url: "../index/exhibitionDetails?id=" + id
			// 	})
			// },
			toArtwork(id) {
				if (this.navChoose == 1) {
					uni.navigateTo({
						url: "../index/artWorkDetails?id=" + id
					})
				} else {
					uni.navigateTo({
						url: "../hypermarket/artDetails?id=" + id
					})
				}
			},
			cancelShow(id, index) {
				cancelCollect(id, this.navChoose).then(res => {
					if (res.result == 0) {
						this.collectArr = [];
						this.getList();
					}
				})
			},
		},
		components: {
			uniLoadMore
		},
		//上拉加载
		onReachBottom() {
			this.loadMoreStatus = 'loading';
			this.showLoadMore = true
			if (this.page * 10 == this.collectArr.length) {
				this.page++
				this.getList()
			} else {
				this.loadMoreStatus = 'noMore'; //没有数据时显示‘没有更多’
			}
		},
	}
</script>

<style lang="scss" scoped>
	.collect {
		&.none {
			height: 100%;
		}
	}

	.nomore {
		text-align: center;

		.haveno {
			margin: 0 auto;
		}
	}

	.nav {
		width: 100%;
		height: 100rpx;
		margin-bottom: 30rpx;
		display: flex;
		justify-content: space-around;

		.nav-box {
			width: 50%;
		}

		.nav-item {
			width: 94rpx;
			margin: 0 auto;
			font-size: 26rpx;
			text-align: center;
			line-height: 94rpx;

			&.active {
				color: rgba(214, 142, 127, 1);
				border-bottom: 6rpx solid rgba(214, 142, 127, 1);
			}
		}
	}

	.exhibit {
		.exhibit-item {
			padding: 30rpx;
			margin: 0 auto 30rpx;
			background: rgba(255, 250, 245, 1);

			.img-box {
				position: relative;
				width: 100%;
				height: 340rpx;

				.img {
					display: block;
					width: 100%;
					height: 100%;
				}
			}

			.content {
				padding: 30rpx 0;


				.title {
					font-size: 28rpx;
					line-height: 28rpx;
					margin-bottom: 16rpx;
					color: #333;
					font-weight: 700;
				}

				.time {
					font-size: 24rpx;
					line-height: 34rpx;
					color: #666;
					margin-bottom: 20rpx;
				}

				.btn {
					width: 110rpx;
					height: 36rpx;
					border-radius: 6rpx;
					font-size: 22rpx;
					line-height: 36rpx;
					color: #feb42f;
					border: 2rpx solid #feb42f;

					text-align: center;
				}

				.text-right {
					font-size: 24rpx;
					line-height: 34rpx;
					color: #666;
					display: flex;
					justify-content: flex-end;

					.collect {
						margin-right: 40rpx;

						.img {
							width: 34rpx;
							height: 34rpx;
							margin-right: 20rpx;
						}
					}

					.location {
						.img {
							width: 28rpx;
							height: 34rpx;
							margin-right: 20rpx;
						}
					}
				}
			}
		}
	}

	.art {
		padding: 30rpx;

		.art-item {
			margin: 0 auto 20rpx;
			background: #fff;
			padding: 30rpx;
			border-radius: .5rem;
			box-shadow: 0px 2px 4px rgba(189, 163, 112, 0.25);
			position: relative;
			display: flex;

			justify-content: space-between;
			align-items: center;

			.img {
				width: 160rpx;
				height: 160rpx;
				margin-right: 30rpx;
			}

			.content {
				flex-grow: 1;
				position: relative;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				max-width: 40vw;


				.content-title {
					font-size: 30rpx;
					line-height: 30rpx;
					color: #443233;
					font-weight: 700;
					// margin-bottom: 20rpx;
				}

				.price {
					font-size: 34rpx;
					// line-height: 24rpx;
					color: #d99082;
					font-weight: 700;
				}

				.type {
					margin: 20rpx 0;
					>text {
						font-size: 22rpx;
						color: #c09089;
						background: #f9f2ea;
						padding: 10rpx;
						margin: 20rpx 0;
						border-radius: 5rpx;
					}

				}



			}

			.btn {
				// position: absolute;
				width: 110rpx;
				height: 40rpx;
				// right: 0;
				// top: 50%;
				// margin-top: -20rpx;
				border: 2rpx solid #fcb735;
				border-radius: 8rpx;
				color: #fcb735;
				font-size: 22rpx;
				line-height: 40rpx;
				text-align: center;
				margin-left: 30rpx;
			}
		}
	}
</style>
